package com.niiwoo.civet.user.service.duboo;

import com.alibaba.dubbo.config.annotation.Service;
import com.niiwoo.civet.user.dto.request.RefreshSMSCodeRequestDTO;
import com.niiwoo.civet.user.service.UserSMSDubboService;
import com.niiwoo.civet.user.service.local.sms.SMSResult;
import com.niiwoo.civet.user.service.local.sms.SMSSenders;
import java.util.Optional;
import org.springframework.beans.factory.annotation.Autowired;


/**
 * 用户短信API实现
 */
@Service(version = "1.0.0")
public class UserSMSServiceDubboImpl implements UserSMSDubboService {


    @Autowired
    SMSSenders smsSender;

    /**
     * 创建短信记录
     */
    @Override
    public boolean createSMS(RefreshSMSCodeRequestDTO requestDTO) {
        return Optional.ofNullable(smsSender.send(requestDTO)).map(SMSResult::getSuccess).orElse(false);
    }

    /**
     * 创建短信记录并返回验证码
     */
    @Override
    public String createSMSAndReturnCode(RefreshSMSCodeRequestDTO requestDTO) {
        return Optional.ofNullable(smsSender.send(requestDTO)).map(SMSResult::getCode).orElse(null);
    }

}
